package com.sinevil.tcpTrans.entity.task;

import com.sinevil.tcpTrans.entity.json.BasicJson;
import com.sinevil.tcpTrans.entity.json.FilePacketJson;
import lombok.SneakyThrows;

import static com.sinevil.tcpTrans.entity.json.handlers.SocketJsonHandle.objectMapper;

/**
 * @Classname FilePacketTask
 * @Description 文件数据包任务
 * @Version 1.0.0
 * @Date 2025/1/5 15:38
 * @Created by sinevil
 */
public class FilePacketTask extends Task{

    @SneakyThrows
    public FilePacketTask(BasicJson filePacketJson) {
        // 指令任务优先级设为1，数值越小优先级越高，这里表示指令优先级最高
        super(8);
        String jsonString = objectMapper.writeValueAsString(filePacketJson);
        this.bytes = transToBytes(jsonString);
    }
    @SneakyThrows
    public FilePacketTask(FilePacketJson filePacketJson) {
        // 指令任务优先级设为1，数值越小优先级越高，这里表示指令优先级最高
        super(8);
        String jsonString = objectMapper.writeValueAsString(filePacketJson);
        this.bytes = transToBytes(jsonString);
    }


    @Override
    public String toString(){
        return String.format("Task{priority:%d, filePacket:%s}",priority,bytes.toString());
    }


}